package com.hwz.controller.admin;

import com.hwz.dto.OrdersCancelDTO;
import com.hwz.dto.OrdersConfirmDTO;
import com.hwz.dto.OrdersPageQueryDTO;
import com.hwz.dto.OrdersRejectionDTO;
import com.hwz.result.PageResult;
import com.hwz.result.Result;
import com.hwz.service.OrderService;
import com.hwz.vo.OrderStatisticsVO;
import com.hwz.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * [一句话描述该类的功能]
 *
 * @author : [Lenovo]
 * @version : [v1.0]
 * @createTime : [2024/3/23 17:24]
 */
@RestController
@RequestMapping("/admin/order")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 取消订单
     * @param ordersCancelDTO
     * @return
     * @throws Exception
     */
    @PostMapping("/cancel")
    public Result cancelOrder(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception {
        log.info("取消订单请求参数：{}", ordersCancelDTO);
        orderService.cancelOrder(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 查取各个订单状态
     * @return
     */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statisticsOrder()
    {
        OrderStatisticsVO OrderStatisticsVO = orderService.statisticsOrder();
        return Result.success(OrderStatisticsVO);
    }

    /**
     * 完成订单
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    public Result completeOrder(@PathVariable("id") Long id)
    {
        orderService.completeOrder(id);
        return Result.success();
    }

    /**
     * 拒绝订单
     * @param ordersRejectionDTO
     * @return
     * @throws Exception
     */
    @PutMapping("/rejection")
    public Result rejectionOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception {
        orderService.rejectionOrder(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 接单
     * @param ordersConfirmDTO
     * @return
     * @throws Exception
     */
    @PutMapping("/confirm")
    public Result confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO) throws Exception {
        orderService.confirmOrder(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 获取订单详情
     * @param orderId
     * @return
     */
    @GetMapping("/details/{id}")
    public Result<OrderVO> getOrderDetails(@PathVariable("id") Long orderId) {
        OrderVO orderVO = orderService.getOrderDetails(orderId);
        return Result.success(orderVO);
    }

    /**
     * 发货
     * @param orderId
     * @return
     */
    @PutMapping("/delivery/{id}")
    public Result deliveryOrder(@PathVariable("id") Long orderId) {
        orderService.deliveryOrder(orderId);
        return Result.success();
    }


    @GetMapping("/conditionSearch")
    public Result<PageResult>  conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {

        PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }
}
